package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.annotation.AutoFill;
import com.sky.dto.SetmealPageQueryDTO;
import com.sky.entity.Setmeal;
import com.sky.enumeration.OperationType;
import io.swagger.models.auth.In;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface SetmealMapper {

    /**
     * 根据分类id查询是否有套餐
     * @param id
     * @return
     */
    @Select("select count(id) from setmeal where category_id =#{categoryId}")
    Integer countByCategoryId(Long id);

    /**
     * 根据id查询套餐表
     * @param id
     * @return
     */
    @Select("select * from setmeal where id = #{id}")
    Setmeal getSetmealById(Long id);

    /**
     * 根据name来查询套餐表
     * @param name
     * @return
     */
    @Select("select * from setmeal where name = #{name}")
    Setmeal getSetmealByName(String name);


    @AutoFill(OperationType.INSERT)
    void insert(Setmeal setmeal);

    /**
     * 分页查询套餐
     * @param setmealPageQueryDTO
     * @return
     */
    Page<Setmeal> getQueryPage(SetmealPageQueryDTO setmealPageQueryDTO);

    /***
     * 批量删除套餐
     * @param id
     */
    @Delete("delete from setmeal where id = #{id}")
    void deleteById(Long id);


    /**
     * 修改套餐表
     * @param setmeal
     */
    @AutoFill(OperationType.UPDATE)
    void update(Setmeal setmeal);

    @Update("update setmeal set status = #{status} where id = #{id}")
    void setStatusById(Integer status, Long id);

    /**
     * 根据菜品id来查询
     * @param dishId
     * @return
     */
    @Select("select s.* from setmeal s left join setmeal_dish d on s.id = d.setmeal_id where d.dish_id = #{dishId}")
    Setmeal getByDishId(Long dishId);
}
